package com.spider.sina.core;

import com.spider.common.entity.sina.SinaBlog;
import com.spider.dao.SinaBlogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

import java.util.Map;

/**
 * < 一句话简述功能 >
 *  新浪博客 入库操作
 *
 * @author bf
 * @create 2018/3/29
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
@Component
public class SinaPipeline implements Pipeline {

    @Autowired
    private SinaBlogMapper sinaBlogMapper;

    @Override
    public void process(ResultItems resultItems, Task task) {
        for (Map.Entry<String, Object> entry : resultItems.getAll().entrySet()) {
            if (entry.getKey().contains("news")) {
                SinaBlog blog=(SinaBlog) entry.getValue();
                sinaBlogMapper.insertSelective(blog);
            }
        }
    }
}